﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TaoLeH.Helper;
using TaoLeH.Helper.Json;
using TaoLeH.Models.Dto;
using TaoLeH.Models.Enum;

namespace TaoLeH.WebApi.Biz
{
    public class DemoService : ApiService
    {
        /// <summary>
        /// 测试方式{}
        /// </summary>
        /// <param name="context"></param>
        public void GetString(ApiContext context)
        {
            ApiHttpResponse apiResponse = new ApiHttpResponse();
            string data = context.DecData;
            //解析data
            var sd = JsonHelper.DeserializeLower(context.DecData);
            string str = sd.GetValue<string>("name");
            //验证参数
            if (string.IsNullOrEmpty(str))
            {
                apiResponse.RetCode = ResultEnum.Fail;
                apiResponse.Message = "参数错误";
                context.ApiHttpResp = apiResponse;
                return;
            }

            apiResponse.RetCode = ResultEnum.Success;
            apiResponse.Data = JsonHelper.Serialize(new { name = str });
            context.ApiHttpResp = apiResponse;
        }
    }
}
